<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<title>速翔网络 - QQ技术：1424445608</title>
	<link rel="stylesheet" type="text/css" href="../c/aui.css" />
	<link rel="stylesheet" type="text/css" href="../c/animate.css" />
	<style>
		body,
		.aui-list,
		.aui-bar-tab {
			background: transparent !important;
			/*background: #000 !important;*/
		}

		.aui-list,
		.aui-list aui-media-list li,
		.aui-list .aui-list-item {
			border: 0 !important;
			background: none
		}

		.aui-list .aui-list-item:active
		,.aui-list:active
		{
			background: none  !important;
		}
		/* 详细UI界面 */

		.view-header {
			background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0));
			background-image: -o-linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0));
			background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0));
			padding-bottom: 2rem;
		}

		.view-header .aui-list-item-media {
			width: 3.5rem;
		}

		.view-header .aui-list-item-text {
			color: #fff;
			font-size: 0.75rem;
		}

		.view-header .aui-list-item-text:nth-last-child(1) {
			font-size: 0.65rem;
			color: #F0F0F0
		}

		.view-header img.close {
			width: 1.8rem;
			height: 1.8rem;
			position: absolute;
			right: 0.75rem;
			top: 1.3rem;
			display: inline-block;
			background-color: rgba(0, 0, 0, 0.2);
			border-radius: 50%;
			text-align: center;
			padding: 0.38rem;
		}

		.view-header .view-renqi {
			padding: 0 1rem;
			color: #fff;
			margin-top: 0.2rem;
		}

		.view-renqi-1 div {
			display: inline-block;
			margin-right: 1rem;
		}

		.view-renqi-1 div span {
			color: #fff;
			font-size: 0.65rem;
			padding-left: 0.15rem;
		}

		.view-renqi-1 div img {
			width: 1rem;
			vertical-align: middle;
			display: inline-block;
		}

		.view-sz {
			background: rgba(0, 0, 0, 0.2) url('../i/zhibo/view-sz.png') no-repeat 0.5rem center;
			background-size: 1rem;
			border-radius: 2rem;
			color: #fff;
			font-size: 0.65rem;
			display: inline-block;
			padding: 0.35rem 1rem;
			margin-top: 0.75rem;
			margin-left: 0.75rem;
			padding-left: 1.8rem;
		}

		.view-footer {
			padding: 0.75rem;
			min-height: 0rem;
			width: 100%;
			background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.3));
			background-image: -o-linear-gradient(rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.3));
			background-image: linear-gradient(rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.3));
		}

		.view-footer .aui-bar-tab-item {
			height: auto;
		}

		.view-footer .view-footer-2,
		.view-footer .view-footer-3 {
			width: 2.4rem;
			margin: 0 auto;
			text-align: center;
		}

		.view-footer .view-footer-2 p,
		.view-footer .view-footer-3 p {
			width: 1.8rem;
			border-radius: 50%;
			background: rgba(0, 0, 0, 0.2);
			text-align: center;
			height: 1.8rem;
			margin: 0 auto;
			padding: 0.5rem;
		}

		.view-footer p.hk {
			background: none;
			padding: 0rem;
			border-radius: 0;
		}

		.view-footer .view-footer-2 img,
		.view-footer .view-footer-3 img {
			text-align: center;
			margin: 0 auto;
			padding: 0.1rem;
		}

		.view-footer .view-footer-1 {
			width: auto;
		}

		.view-footer .view-footer-1 p {
			background: rgba(0, 0, 0, 0.2);
			border-radius: 3rem;
			height: 1.8rem;
			line-height: 1.8rem;
			text-align: left;
			padding-left: 0.75rem;
			font-size: 0.65rem;
			margin-right: 1rem;
			color: #fff;
		}

		.view-footer .view-footer-2 {}

		.view-footer .view-footer-3 {}

		.view-footer div {}
		/* 聊天室 */

		.view-liaotian::-webkit-scrollbar {
			width: 0;
			height: 0;
			display: none;
		}

		.view-liaotian {
			height: 10rem;
			overflow-x: hidden;
			overflow-y: scroll;
			-webkit-overflow-scrolling: touch;
			width: 90%;
			padding-bottom: 1rem;
		}
		.view-liaotian .text{
			-webkit-overflow-scrolling: touch;

		}
		.view-liaotian .text img{
			display: inline-block;
			vertical-align: middle;
		}

		.view-liaotian p {
			font-size: 0.75rem;
			border-radius: 0.75rem;
			margin-top: 0.3rem;
			display: inline-block;
			background: rgba(0, 0, 0, 0.2);
			padding: 0.15rem 0.5rem;
			clear: both;
			line-height: 1.1rem;
			color: #FFD600 !important;
			letter-spacing: 1px;
		}

		.view-liaotian p span {
			background: #F8091C;
			font-size: 0.65rem;
			border-radius: 0.35rem;
			padding: 0.1rem 0.3rem;
			margin-right: 0.35rem;
			color: #fff !important;
			;
		}
		/* 标志红色颜色 */

		.view-liaotian p span.b0 {
			background: #FF0000 !important;
		}
		/* 标志红色颜色  系统专用 */

		.view-liaotian p span.b1 {
			background: #FF0000 !important;
		}
		/* 标志红色颜色 直播专用 */

		.view-liaotian p span.b2 {
			background: #FE3881 !important;
		}
		/* 白色颜色 */

		.view-liaotian p.p {
			color: #fff !important;
			;
		}
		/* 警告颜色 */

		.view-liaotian p.p0 {
			color: #F8091C !important;
			;
		}
		/* 提示颜色*/

		.view-liaotian p.p1 {
			color: #FF742D !important;
			;
		}
		/* 主播颜色 */

		.view-liaotian p.p2 {
			color: #FFD600 !important;
			;
		}
		/* 用户颜色 */

		.view-liaotian p.p3 {
			color: #FFD600 !important;
			;
		}

		.kaishi .kaishi-1 img {}

		.kaishi .kaishi-1 p {
			color: #fff;
			font-size: 0.75rem;
			padding-top: 0.35rem;
			text-align: center;
		}

		.kaishi .kaishi-1 div {
			width: 33.33333%;
		}

		.kaishi .kaishi-1 img {
			width: 1.2rem;
			margin: 0 auto;
		}

		.kaishi-2 {
			background: #F95555;
			color: #fff;
			border-radius: 0.35rem;
			text-align: center;
			width: 80%;
			margin: 1rem auto;
			padding: 0.75rem 0;
		}
		.view_frm_msg {
			position: relative;
			width: 250px;
			background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0) 80%);
			border-radius: 5rem;
			animation: bounceInLeft 1s;
			margin-left: 0.5rem;
			transition: max-height 3s;
		}


		.view_frm_msgs {
			padding: 0.25rem;
			position: relative;
			margin-top: 1rem;
			position: relative;
			-webkit-box-sizing: border-box;
			box-sizing: border-box;
			display: -webkit-box;
			display: -webkit-flex;
			display: flex;
			-webkit-box-pack: justify;
		}


		.view_frm_msg .a1 {
			width: 54px;
			height: 54px;
			border-radius: 50%;
			margin-right: 0.35rem;
			border-radius: 50%;
		}

		.view_frm_msg .a2 {
			width: 120px;
			line-height: 25px;
		}

		.view_frm_msg .a2 h2 {
			color: #fff;
		}

		.view_frm_msg .a2 p {
			color: #FFD600
		}

		.view_frm_msg .a3 {
			position: absolute;
			right: 0;
			top: 0rem;
			width: 5rem;
			margin-top: -1rem;
			margin-right: 0rem;
		}

		@keyframes bounceInLeft {
			0% {
				opacity: 0;
				transform: translate3d(-3000px, 0, 0);
			}
			60% {
				opacity: 1;
				transform: translate3d(25px, 0, 0);
			}
			75% {
				transform: translate3d(-10px, 0, 0);
			}
			90% {
				transform: translate3d(5px, 0, 0);
			}
			100% {
				transform: none;
			}
		}
	</style>
</head>

<body>
	<header class="view-header">
		<ul class="aui-list aui-media-list">
			<li class="aui-list-item aui-list-item-middle">
				<div class="aui-media-list-item-inner">
					<div class="aui-list-item-media">
						<img tapmode onclick="u()" src="../i/touxiang.png" class="aui-img-round aui-list-img-sm">
					</div>
					<div class="aui-list-item-inner">
						<div class="aui-list-item-text"><span tapmode onclick="u()"></span></div>
						<div class="aui-list-item-text" id="fensi">
							<span tapmode onclick="u()" tapmode onclick="u()">0 粉丝</span>
						</div>
					</div>
				</div>
				<img class="close" src="../i/x.png" tapmode onclick="c()" />
			</li>
		</ul>
		<div class="view-renqi aui-card-list-footer">
			<div class="view-renqi-1">
				<!--	<div>
						<img src="../../image/zhibo/view-renqi-1.png" />
						<span>0</span>
					</div>-->
				<div tapmode onclick="liwu_user();">
					<img src="../i/zhibo/view-renqi-2.png" />
					<span>收入 </span>
					<span id="zhu_zuan" data-num="0">0</span>
				</div>
			</div>
			<div class="view-renqi-2">
				<span>0</span> 人气
			</div>
		</div>
		<!--<div class="view-sz">
				设置粉丝团
			</div>-->

	</header>
	<footer class="view-footer  aui-bar-tab">
		<div class="kaishi" style="display: none">
			<div class="kaishi-1 aui-card-list-footer">
				<div tapmode onclick="switchCamera()">
					<img src="../i/zhibo/sz-1.png" />
					<p>
						翻转
					</p>
				</div>
				<div tapmode onclick="setFilter()">
					<img src="../i/zhibo/sz-2.png" />
					<p>
						滤镜
					</p>
				</div>
				<!-- <div tapmode onclick="setScreen()">
					<img src="../i/zhibo/sz-4.png" />
					<p>
						横屏竖屏
					</p>
				</div> -->
			</div>
			<div class="kaishi-2" tapmode onclick="kaishi()">
				开始直播
			</div>
		</div>
		<style>
		#shop{
			width: 4rem;
			display: none;
			position: fixed;
			right: 0;
			top: 0;
			margin-top: 50%;
			opacity:0;
			margin-right: 0.75rem;
		}
		#shop .view img{
			border-top-left-radius: 0.25rem;
			border-top-right-radius: 0.25rem;
		}
		#shop .pay{
			background:#FE2C55;
			text-align: center;
			width: 100%;
			margin: 0 auto;
			border-bottom-left-radius: 0.25rem;
			border-bottom-right-radius: 0.25rem;
			font-size: 0.6rem;
			padding: 0.25rem 0;
			color: #fff;
		}
		</style>
		<div id="shop" tapmode onclick="show_url()">
			<div class="view">
				<img src="" >
				<div class="pay">
					商品详细>>
				</div>
			</div>
		</div>
		<div class="view-liaotian" id="view-liaotian">
			<div class="text">
				<p class="p1"></p>
			</div>
		</div>
		<div class="aui-bar aui-margin-b-15">
			<div class="aui-bar-tab-item view-footer-1" tapmode onclick="input()">
				<p>
				</p>
			</div>
			<div class="aui-bar-tab-item view-footer-2">
				<p class="hk" tapmode onclick="fx();"><img src="../i/zhibo/view-fx.png" />
				</p>
			</div>
			<div class="aui-bar-tab-item view-footer-2">
				<p class="hk" tapmode onclick="liwu();"><img src="../i/zhibo/view-liw.png" />
				</p>
			</div>
			<div class="aui-bar-tab-item view-footer-3">
				<p style="display: none" tapmode onclick="sz();"><img src="../i/zhibo/fenlei.png" />
				</p>
				<p class="hk" tapmode onclick="xin();"><img src="../i/zhibo/view-xin.png" />
				</p>
			</div>
		</div>
	</footer>


</body>
<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript" src="../j/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
	var publisher, chat, filterOn, screenOrientation = 'portrait_up',
		torchOn, UIChatBox, player, applause, input_ok = false;
	var session = {};
	apiready = function() {
_user = _getPrefs('_user');
			applause = api.require('applause');
			userInfo()
				//保持屏幕唤醒
			api.setKeepScreenOn({
				keepOn: true
			});
			//监听网络情况
			api.addEventListener({
				name: 'offline'
			}, function(ret, err) {
				liaotianshi('网络异常', 'p');
			});
			api.addEventListener({
				name: 'online'
			}, function(ret, err) {
				liaotianshi('网络恢复', 'p');
			});
			// 应用从后台回到前台事件
			api.addEventListener({
				name: 'resume'
			}, function(ret, err) {
				if(api.systemType == 'ios' && api.pageParam['ret']['role'] == 2){
					publisher.publish();
				}
			});
			//  console.log(JSON.stringify(api.pageParam));

			$api.fixStatusBar($api.dom('.view-header'));
			$api.fixStatusBar($api.dom('#shop'));
			$api.fixTabBar($api.dom('.view-footer'))
			UIChatBox = api.require('UIChatBox');
			api.parseTapmode();
			if (api.pageParam['ret']['role'] == 2) {
				session = {
					roomId: api.pageParam['roomId'],
					password: api.pageParam['anchorPwd'],
					nickname: api.pageParam['nickname']
				};
				$('.view-footer .kaishi').show();
				$('.view-footer .view-liaotian').hide();
				$('.view-footer .aui-bar').hide();
				// 底部设置直播功能
				$('.view-footer-3 .hk').remove();
				$('.view-footer-3 p').show();
				// 结束
				publisher = api.require('gotyeLivePublisher');
				publisher.init({
					session: session
				});
				//liaotianshi('正在连接直播服务器', 'p');
				//在推流之前，需要先打开设备的摄像头
				publisher.startPreview({
					preview: 'zhibo_view_frame',
					position: 'front',
					rect: {
						x: 0,
						y: 0,
						w: api.frameWidth,
						h: api.frameHeight
					}
				}, function(ret, err) {
					if (ret) {
						//登录，此时并未正式开启直播，如要开启，还需触发startPublisher
						publisher.login({
							force: true
						}, function(ret, err) {
							if (ret) {
								//	liaotianshi('连接直播服务器成功', 'p');
							} else {
								liaotianshi('连接直播服务器失败', 'p');
							}
							api.execScript({
								script: '_loadingCloes()'
							});
						});
					} else {
						liaotianshi('打开设备摄像头失败', 'p');
						api.execScript({
							script: '_loadingCloes()'
						});
					}
				});
				publisher.addEventListener({
					name: 'connected'
				}, function(ret, err) {
					liaotianshi('连接直播服务器成功', 'p');
				});
				publisher.addEventListener({
					name: 'disconnected'
				}, function(ret, err) {
					liaotianshi('直播服务器断开连接1', 'p');
				});
				publisher.addEventListener({
					name: 'reconnecting'
				}, function() {
					liaotianshi('直播服务器重新连接中', 'p');
				});
				publisher.addEventListener({
					name: 'error'
				}, function(ret, err) {
					liaotianshi(ret.description, 'p');
				});
				publisher.addEventListener({
					name: 'forceLogout'
				}, function() {
					liaotianshi('您的账号在另外的设备登录，当前设备需强制踢下线1', 'p');
					api.alert({
						msg: '您的账号在另外的设备登录，当前设备需强制踢下线',
						buttons: ['知道了']
					}, function(ret, err) {
						if (ret.buttonIndex == '1') {
							_close();
						}
					});
				});
			} else {
				session = {
					roomId: api.pageParam['roomId'],
					password: api.pageParam['userPwd'],
					nickname: api.pageParam['nickname']
				};
				xin_donghua();
				//观众视角，初始化播放器
				// player = api.require('gotyeLivePlayer');
				// player.init({
				// 	session: session
				// });
				// player.play({
				// 	playView: "zhibo_view_frame",
				// 	rect: {
				// 		x: 0,
				// 		y: 0,
				// 		w: api.frameWidth,
				// 		h: api.frameHeight
				// 	}
				// });
				//aspectFill表示保持比例撑满，视频会按照比例放大直到撑满屏幕为止
				// player.setDisplayMode({
				// 	mode: 'aspectFill'
				// });
				// //根据实际业务需求加入监听事件
				// player.addEventListener({
				// 	name: 'connected'
				// }, function(ret, err) {
				// 	if (ret) {
				// 		console.log(JSON.stringify(ret));
				// 		liaotianshi('连接直播服务器成功', 'p');
				// 	} else {
				// 		console.log(JSON.stringify(err));
				// 	}
				// });
				// player.addEventListener({
				// 	name: 'disconnected'
				// }, function(ret, err) {
				// 	liaotianshi('直播服务器断开连接2', 'p');
				// });
				// player.addEventListener({
				// 	name: 'error'
				// }, function(ret, err) {
				// 	liaotianshi(ret.description, 'p');
				// });
				// player.addEventListener({
				// 	name: 'liveStart'
				// }, function(ret, err) {
				// 	liaotianshi('直播开始', 'p');
				// });
				// player.addEventListener({
				// 	name: 'liveStop'
				// }, function(ret, err) {
				// 	liaotianshi('直播结束', 'p');
				// });
				api.execScript({
					script: '_loadingCloes()'
				});
			}
			//初始化聊天信息
			//	liaotianshi('正在连接聊天服务器','p');
			chat = api.require('gotyeLiveChat');
			chat.init(session);
			chat.login(function(ret, err) {
				if (ret) {
					input_ok = true;
					//	console.log('login：' + JSON.stringify(ret));
					localId = ret.account;
					// liaotianshi('连接聊天服务器成功', 'p');
					zhubo_info(); // 更新人气和主播钻石
					jinru(); // 提醒用户进入主播间
				} else {
					//	console.log('login：' + JSON.stringify(err));
					liaotianshi('连接聊天服务器失败', 'p');
				}
			});
			//监听收到的消息
			chat.addEventListener({
				name: 'receiveMsg'
			}, function(ret, err) {
				if (ret) {
					// console.log('收到消息ret：' + JSON.stringify(ret));
					if (ret.status == 0) {

						var extra = eval('(' + ret.extra.replace(/}{/, ',') + ')');

						if (extra.type == '100') {
							// 用户进入直播间
							liaotianshi("<b style='color:#FFD600'>" + extra.username + "</b>进入了直播间", 'p');
						} else if (extra.type == '99999') {
							// 礼物动画
							//	console.log('收到礼物：' + JSON.stringify(extra.liwu_data));
							liwu_donghua(extra.liwu_data)
						} else {

							var span = "";
							if (extra.role == 2) {
								span = '<span class="b2">主播</span>';
							}
							liaotianshi(extra.username + " : " + ret.text, 'p', span);
						}


					}
				} else {
					console.log('收到消息err：' + JSON.stringify(ret));
				}
			});
			// 监听登录设备
			chat.addEventListener({
				name: 'forceLogout'
			}, function(ret, err) {
				liaotianshi('您的账号在另外的设备登录，当前设备需强制踢下线2', 'p');
				api.alert({
					msg: '您的账号在另外的设备登录，当前设备需强制踢下线',
					buttons: ['知道了']
				}, function(ret, err) {
					if (ret.buttonIndex == '1') {
						_close();
					}
				});
			});
			// 监听输入框滚动
			//			UIChatBox.addEventListener({
			//				target : 'inputBar',
			//				name : 'move'
			//			}, function(ret, err) {
			//				if (ret) {
			//				//	console.log("inputBar:" + JSON.stringify(ret));
			//					if (ret.panelHeight) {
			//					} else {
			//						//UIChatBox.close();
			//					}
			//				}
			//			});


		}
		// 开始直播
	function kaishi() {
		//liaotianshi('直播已开始', 'p');
		$('.view-footer .kaishi').hide();
		$('.view-footer .view-liaotian').show();
		$('.view-footer .aui-bar').show();
		 
		// 开始直播
		publisher.publish();
		zhibo_edit(1);

		// 关闭直播	publisher.unpublish();
	}

	//获取观众总数及观众列表信息		(代码报废)
	function initUserList() {
		//	zhubo_info();	// 更新人气和主播钻石
		jinru(); // 提醒用户进入主播间
		chat.queryUserList({
			index: 1,
			total: 20
		}, function(ret, err) {
			if (ret) {
				// console.log(JSON.stringify(ret))
				return;
				var ht_user = '<div class="viewer-list-item aui-ellipsis-1 aui-padded-l-15"><img class="crown" src="../i/publisher/crown.png" />主播</div>';
				for (var i = 0; i < ret.entities.length; i++) {
					ht_user += '<div class="viewer-list-item aui-ellipsis-1" data-account="' + ret.entities[i].account + '" tapmode onclick="onUserClick(this);event.cancelBubble=true;">' + ret.entities[i].nickname + '</div>';
				}
				$('#viewerList').html(ht_user);
			} else {
				console.log(JSON.stringify(err));
			}
		});
	}
	// 进入直播间
	function jinru() {

		liaotianshi("<b style='color:#FFD600'>" + _user.username + "</b>进入了直播间", 'p');
		var json = {
			uid: _user.id,
			username: _user.username,
			img: _user.img,
			role: api.pageParam['ret']['role'],
			type: 100 // 进入直播间，发送内容其他用户接受提示
		}
		var json = JSON.stringify(json); // 额外自定义参数
		// 发送文字内容
		sendText('1', json)
			// 结束
	}

	//设置前后摄像头
	function switchCamera() {
		publisher.switchCamera();
	}

	//设置横屏竖屏
	function setScreen() {
		if (screenOrientation == 'portrait_up') {
			screenOrientation = 'landscape_left';
		} else {
			screenOrientation = 'portrait_up';
		}
		api.setScreenOrientation({
			orientation: screenOrientation
		});
	}

	//设置闪光灯
	function setTorch() {
		if (!torchOn) {
			torchOn = true;
		} else {
			torchOn = false;
		}
		publisher.setTorchOn({
			on: torchOn
		});
	}

	//设置滤镜
	function setFilter() {
		if (!filterOn) {
			filterOn = true;
			publisher.setFilter({
				filter: 'smoothSkin'
			})
			publisher.setSmoothSkinFactor({
				factor: 0.9
			})
		} else {
			filterOn = false;
			publisher.setFilter({
				filter: 'normal'
			})
		}
	}

	// 文字发布聊天到界面
	function liaotianshi(text, addClass, span) {
		if(text == '直播还未开始'){
			return;
		}
		if(text == '获取直播URL出错'){
			return;
		}
		xin();
		// console.log(text)
		var html = '<div class="text">';
		// html += '<p class="' + addClass + '">' + span + (addClass == 'p' ? '' : (_user.username ? _user.username + " : " : '')) + text + '</p>';
		html += '<p class="' + addClass + '">' + (span ? span : '') + _text(text) + '</p>';
		html += '</div>'
		var _this = $('#view-liaotian');
		_this.append(html);
		_this.animate({
			scrollTop: document.getElementById("view-liaotian").scrollHeight
		}, 500);
	}

	// 打开设置
	function sz() {
		var name = 'zhibo_view_frm_sz'
		api.openFrame({
			name: name,
			url: _h_w + name + '.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			animation: {
				type: "movein", //动画类型（详见动画类型常量）
				subType: "from_bottom", //动画子类型（详见动画子类型常量）
				duration: 300
			},
			bounces: false,
			bgColor: 'rgba(0,0,0,0)',
			vScrollBarEnabled: false,
			hScrollBarEnabled: false
		});
	}

	// 打开聊天框
	function input() {
		if (!input_ok) {
			return;
		}
		UIChatBox.open({
			autoFocus: true,
			placeholder: _getPrefs('_config').zhibo.input_text,
			isClose: true,
			maxRows: 4,
			emotionPath: _i + 'UIChatBox/emotion',
			styles: {
				inputBar: {
					borderColor: '#000',
					bgColor: '#000',
					textColor: '#fff'
				},
				inputBox: {
					borderColor: '#000',
					bgColor: '#000'
				},
				emotionBtn: {
					normalImg: _i + 'UIChatBox/emotionBtn.png'
				},
				keyboardBtn: { //JSON对象；键盘按钮样式
					normalImg: _i + 'UIChatBox/keyboardBtn.png'
				},
				recordBtn: {
					normalBg: '#c4c4c4',
					activeBg: '#999999',
					color: '#000',
					size: 14
				},
				indicator: {
					target: 'both',
					color: '#c4c4c4',
					activeColor: '#9e9e9e'
				},
				sendBtn: {
					titleColor: '#fff',
					bg: '#000',
					activeBg: '#46a91e',
					titleSize: 14
				}
			}
		}, function(ret, err) {
			if (ret) {
				if (ret.eventType == 'show') {
					//	UIChatBox.popupKeyboard();
				}
				// 发送按钮
				if (ret.eventType == 'send') {
					// 开始发送
					if (ret.msg) {
						var span = "";
						if (api.pageParam['ret']['role'] == 2) {
							span = '<span class="b2">主播</span>';
						}
						liaotianshi(_user.username + " : " + ret.msg, 'p', span);
						var json = {
							uid: _user.id,
							username: _user.username,
							img: _user.img,
							role: api.pageParam['ret']['role']
						}
						extra = JSON.stringify(json); // 额外自定义参数
						// 发送文字内容
						sendText(ret.msg, extra)
							// 关闭键盘
						UIChatBox.closeKeyboard();
						// 关闭输入框
						UIChatBox.close();
					} else {
						_msg('请说输入内容')
					}
				}
			} else {
				//	console.log("err：" + JSON.stringify(err));
			}
		});
	}
	// 封装发送文本内容
	function sendText(text, extra) {
		chat.sendText({
			text: text,
			extra: extra
		}, function(ret, err) {
			if (err) {
				console.log(JSON.stringify(err))
				liaotianshi("内容发送失败，错误代码：" + err.code + "，原因：" + err.description);
			}
		});
	}

	//清除房间验证信息，销毁session实例。退出直播间时调用
	function destroyRoomSession() {
		var core = api.require('gotyeLiveCore');
		core.destroyRoomSession(session);
	}

	// 关闭直播
	function c() {
		if(api.pageParam['url']){
			api.execScript({
			    script: 'guanbi();'
			});
		}
		if (api.pageParam['ret']['role'] == 2) {
			_loading('正在关闭。。。');
			// 断开主播端与推流服务器的连接，不停止预览
			publisher.unpublish();
			// 退出主播间直播账号的登录。仅模式一有效
			publisher.logout();
			// 断开主播端与推流服务器的连接并停止预览
			publisher.stop();
		} else {
			//停止直播播放
			// player.stop();
		}
		//登出聊天
		chat.logout();
		//销毁房间验证信息
		destroyRoomSession();
		api.setKeepScreenOn({
		    keepOn: false
		});
		if (api.pageParam['ret']['role'] == 2) {
			_ajax('zhibo/zhubo_info', function(ret, err) {
				_loadingCloes();
				_close();
			})
		} else {
			_close();
		}

		//			api.confirm({
		//			    title: 'testtitle',
		//			    msg: 'testmsg',
		//			    buttons: ['确定', '取消']
		//			}, function(ret, err) {
		//			    var index = ret.buttonIndex;
		//			});
	}

	// 主播信息
	function userInfo() {
		$('.view-liaotian .text p').html(_getPrefs('_config').zhibo.content);
		$('.view-footer-1 p').html(_getPrefs('_config').zhibo.input_text);
		var img = api.pageParam['user'] ? api.pageParam['user']['img'] : '';
		var nickname = api.pageParam['user'] ? api.pageParam['user']['username'] : '';
		var fensi = api.pageParam['user'] ? api.pageParam['user']['fensi'] : '';
		if (api.pageParam['ret']['role'] == 2) {
			img = _user.img;
			nickname = _user.nickname;
			fensi = _user.fensi;
		}
		if (img) {
			if(api.pageParam['url']){
				$('.view-header ul img.aui-img-round').attr('src', img);
			}else{
				$('.view-header ul img.aui-img-round').attr('src', _img(img, 100));
			}

		}
		var _this = $('.view-header ul .aui-list-item-text span');
		_this.eq(0).text(nickname);
		_this.eq(1).text(fensi ? fensi : 0 + ' 粉丝');

	}
	// 心动画
	function xin_donghua() {
		// 心
		var y = $('.view-footer-3').offset().top
		var w = $('.view-footer-3 img').width();
		var h = $('.view-footer-3 img').height();
		var x = $('.view-footer-3').offset().left;
		applause.showAppLause({
			rect: {
				x: x,
				y: y,
				w: w,
				h: h
			},
			placeholderImg: _i + "zhibo/view-xin-t.png",
			iamges: [
				_i + 'zhibo/view-xin.png',
			],
			isShowNum: false,
			applauseNum: 0,
			fixedOn: api.frameName,
			fixed: true
		},function(ret,err){
			// console.log(JSON.stringify(ret))
			if(ret.eventType == 'click'){
				// _zhen();
			}else if(ret.eventType == 'show'){
				xin_donghua_moni();
			}
		});
		// _zhen();
	}
	function xin_donghua_moni(){
		xin();
		setTimeout(function(){
			 xin_donghua_moni();
		},Math.floor(Math.random()*20)*100)
	}
	// 打开主播个人主页
	function u() {
		if(api.pageParam['url']){
			return;
		}
		var uid = api.pageParam['uid'] ? api.pageParam['uid'] : '';
		if (api.pageParam['ret']['role'] == 2) {
			uid = _user.id;
		}
		_u(uid);
	}

	// 礼物
	function liwu() {
		var name = 'zhibo_view_frm_liwu'
		api.openFrame({
			name: name,
			url: _h_w + name + '.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			animation: {
				type: "movein", //动画类型（详见动画类型常量）
				subType: "from_bottom", //动画子类型（详见动画子类型常量）
				duration: 300
			},
			bounces: false,
			pageParam: api.pageParam,
			bgColor: 'rgba(0,0,0,0)',
			vScrollBarEnabled: false,
			hScrollBarEnabled: false
		});
	}
	// 礼物用户榜单
	function liwu_user() {
		var name = 'zhibo_view_frm_liwu_user';
		api.openFrame({
			name: name,
			url: _h_w + name + '.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			animation: {
				type: "movein", //动画类型（详见动画类型常量）
				subType: "from_bottom", //动画子类型（详见动画子类型常量）
				duration: 300
			},
			bounces: false,
			pageParam: api.pageParam,
			bgColor: 'rgba(0,0,0,0)',
			vScrollBarEnabled: false,
			hScrollBarEnabled: false
		});
	}
	// 心
	function xin() {
		applause.clickAppLause();
	}
	// 发送礼物ajax
	function liwu_ajax(data) {
		data = eval('(' + data.replace(/}{/, ',') + ')');
		liaotianshi(_user.username + "赠送<b style='color:#FF742D'>" + data.title + "</b>", 'p');
		data.user = {};
		data.user.id = _user.id;
		data.user.img = _user.img;
		data.user.username = _user.username;
		liwu_donghua(data);
		liwu_msg(data);
		var _this = $('#zhu_zuan');
		var num = parseInt(_this.data('num')) + parseInt(data.money);
		_this.data('num', num);
		_this.text(_num(num));
		_msg('赠送成功');
		_ajax('zhibo/liwu_money', function(ret, err) {
			_userInfo();
			if (ret) {
				if (ret.err) {
					_alert(ret.err)
				}
				//	console.log(JSON.stringify(ret))
			} else {
				console.log(JSON.stringify(err))
			}
		}, {
			id: data.id,
			uid_zhu: api.pageParam['uid']
		})
	}
	// 更新主播信息
	function zhubo_info() {
		// if(api.pageParam['url']){
		// 	return;
		// }
		chat.getRoomMemberCount(function(ret, err) {
			if (ret) {
				$('.view-renqi-2 span').text(_num(ret.count));
			}
		});
		var url = api.pageParam['ret']['role'] == 2 ? 'zhibo/zhubo_info' : 'user/info';
		var url = 'zhibo/zhubo_info';
		_ajax(url, function(ret, err) {
			if (ret) {

				if(ret.err){
					console.log(JSON.stringify(ret))
				}else{
					// console.log(JSON.stringify(ret))
				}
				show_data = ret.show_data;
				shop_show();
				var _this = $('#zhu_zuan');
				_this.data('num', ret.zhibo_zuan_s);
				_this.text(_num(ret.zhibo_zuan_s_));
				$('#fensi').html(_num(ret.fensi) + " 粉丝");
				// $('.view-renqi-2 span').text(_num(ret.renqi));
				setTimeout(function() {
					zhubo_info();
				}, 5000)
			} else {
					console.log(JSON.stringify(err))
			}
			//	zhubo_info();
		}, {
			uid: api.pageParam['uid'] ? api.pageParam['uid'] : _user.id,
			zhibo_data:api.pageParam
		})
	}
	// 礼物动画
	function liwu_donghua(data) {

		var x = 100;
		var y = 0;
		var rand = parseInt(Math.random() * (x - y + 1) + y);
		var html = '<div class="view_frm_msg" id="view_frm_msg_' + rand + '"><div class="view_frm_msgs"><img class="a1" src="' +( data.user.img ? _img(data.user.img,60) : '../i/touxiang.png') + '" /><div class="a2"><h2 class="aui-font-size-14 aui-ellipsis-1">' + data.user
			.username + '</h2><p class="aui-font-size-14 aui-ellipsis-1">' + data.title + '</p></div><img class="a3" src="' + _sx_qiniu+data.img+"?imageView2/1/w/100/format/png" + '" /></div></div>';
		$('header').append(html);
		setTimeout(function() {
			$('#view_frm_msg_' + rand).animate({
				opacity: 0,
				top: '-2rem',
			}, 100, function() {
				$(this).remove();
			})
		}, 2000)
	}
	// 礼物给聊天室
	function liwu_msg(data) {
		// 发送其他用户接受
		var json = {
			uid: _user.id,
			username: _user.username,
			img: _user.img,
			role: api.pageParam['ret']['role'],
			type: 99999, // 让其他用户收到礼物
			liwu_data: data
		}
		var extra = JSON.stringify(json); // 额外自定义参数
		// 发送文字内容
		sendText('1', extra)
			// 发送结束
	}

	function _num(a) {
		if (a > 10000) {
			a = (a / 10000).toFixed(2) + '万';
		}
		return a;
	}
	// 关闭直播
	function zhibo_edit() {
		_ajax('zhibo/zhibo_edit')
	}
	//  商品
	var show_data;
	function shop_ajax(){
		_ajax('zhibo/shop_show/id/1',function(ret,err){
			// console.log(JSON.stringify(ret)+JSON.stringify(err))
			show_data = ret;
			if(ret){
				api.imageCache({
						url: _img(show_data.img,300,450),
						thumbnail: false
				}, function(ret, err) {
						if (ret) {
								if (!ret.status) {
										ret.url = show_data.img;
								}
								show_data.img = ret.url
								// console.log(show_data.img)
								shop_show();
						}
				});
			}else{

			}
		})
	}

	function shop_show(){
		if(!show_data){
			return;
		}
		api.imageCache({
				url: _img(show_data.img,300,450),
				thumbnail: false
		}, function(ret, err) {
				if (ret) {
						if (!ret.status) {
								ret.url = show_data.img;
						}
						show_data.img = ret.url
						// 缓存结束
						var _this = $('#shop');
						// console.log(_this.data('id') +":"+ data.id)
						if(_this.data('id') == show_data.id){
							return;
						}
						_this.data('id',show_data.id);
						$('#shop img').attr('src',show_data.img);
						_this.show();
						_this.addClass('animated bounceIn')
				}
		});
	}
	// 商品跳转
	function show_url(){
		_tan({url:'zhibo_view_frm_show',data:show_data})
	}
	function fx(){
		var sharedModule = api.require('shareAction');
		sharedModule.share({
				text: _getPrefs('_config').zhibo.fx_text,
				type: 'url',
				path: _sx_gurl,
				images:_sx_gurl + '/public/style/image/logos.png',
				thumbnail:_sx_gurl + '/public/style/image/logos.png',
		});
	}
</script>

</html>
